import 'package:equatable/equatable.dart';
import 'package:backend.core/core/domain/entities/api/app_store/api_app_store_purchased_subscription_expiration_reason.dart';

const kApiAppStoreCustomerCancellationPurchasedSubscriptionExpirationReasonValue =
    'customer_cancellation';
const kApiAppStoreBillingErrorPurchasedSubscriptionExpirationReasonValue = 'billing_error';
const kApiAppStorePriceIncreasePurchasedSubscriptionExpirationReasonValue = 'price_increase';
const kApiAppStoreUnavailablePurchasePurchasedSubscriptionExpirationReasonValue =
    'unavailable_purchase';

class ApiAppStorePurchasedSubscriptionExpirationReasonDto extends Equatable {
  const ApiAppStorePurchasedSubscriptionExpirationReasonDto._internal({
    required this.expirationReasonString,
  });

  final String expirationReasonString;

  @override
  List<Object?> get props {
    return [
      expirationReasonString,
    ];
  }

  factory ApiAppStorePurchasedSubscriptionExpirationReasonDto.fromEntity(
      ApiAppStorePurchasedSubscriptionExpirationReason expirationReason) {
    late final String expirationReasonString;

    if (expirationReason == ApiAppStorePurchasedSubscriptionExpirationReason.customerCancellation) {
      expirationReasonString =
          kApiAppStoreCustomerCancellationPurchasedSubscriptionExpirationReasonValue;
    } else if (expirationReason == ApiAppStorePurchasedSubscriptionExpirationReason.billingError) {
      expirationReasonString = kApiAppStoreBillingErrorPurchasedSubscriptionExpirationReasonValue;
    } else if (expirationReason == ApiAppStorePurchasedSubscriptionExpirationReason.priceIncrease) {
      expirationReasonString = kApiAppStorePriceIncreasePurchasedSubscriptionExpirationReasonValue;
    } else if (expirationReason ==
        ApiAppStorePurchasedSubscriptionExpirationReason.unavailablePurchase) {
      expirationReasonString =
          kApiAppStoreUnavailablePurchasePurchasedSubscriptionExpirationReasonValue;
    }

    return ApiAppStorePurchasedSubscriptionExpirationReasonDto._internal(
      expirationReasonString: expirationReasonString,
    );
  }

  @override
  String toString() {
    return expirationReasonString;
  }
}
